<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
  String _id=request.getParameter("_");
  String jsessionid = session.getId();
%>

        <div class="panel">
            <div class="panel-heading">
                <ul class="nav nav-tabs">
                    <li class="active"><a  href="#s1" id="first1" data-toggle="tab">发文申请表</a></li>
                    <li class="disabled"><a  href="#s2" id="other1" data-toggle="tab">附件修订</a></li>
                </ul>
            </div>

            <div class="tab-content">
                <div class="tab-pane fade in active" id="s1">
                 <form id="form_dispatch_input" class="form-horizontal">
                    <input type="hidden" name="keyId" id="keyId" value="${dispatch.id}"/>
                    <input type="hidden" name="curDutyId" id="curDutyId" value=""/>
                     <div  class="panel-heading header" >
                         <h3 class="panel-title" id="title">发文申请表</h3>
                     </div>
                    <div class="form-group">
                        <label class="col-md-2 control-label">发文类别<i class="fa fa-asterisk txt-color-red"></i></label>
                        <div class="col-md-6">
                            <input type="text" name="typedictId" id="typedictId" class="form-control" disabled  value="${dispatch.type.name}" >
                        </div>
                    </div>
                     <div class="form-group">
                         <label class="col-md-2 control-label"> 发文标题<i class="fa fa-asterisk txt-color-red"></i></label>
                         <div class="col-md-6">
                             <input type="text"  name="title" id="title1"  class="form-control" disabled  value="${dispatch.title}" >
                         </div>
                     </div>

                     <div class="form-group">
                         <label class="col-md-2 control-label">文件编号<i class="fa fa-asterisk txt-color-red"></i></label>
                         <div class="col-md-6">
                             <input type="text"  name="fileNo" id="fileNo"  class="form-control" disabled value="${dispatch.fileNo}">
                         </div>
                     </div>

                     <div class="form-group">
                         <label class="col-md-2 control-label">
                             发文对象<i class="fa fa-asterisk txt-color-red"></i>
                         </label>
                         <div class="col-md-6">
                             <div class="radio">
                                 <input type="radio" name="object" id="object1" value="1" class="magic-radio" <c:if test='${dispatch == null || dispatch.object == null || dispatch.object=="1"}'> checked</c:if> disabled>
                                 <label for="object1">全体员工</label>
                                 <input type="radio" name="object" id="object2" value="2" class="magic-radio" <c:if test='${dispatch.object=="2"}'>checked</c:if>  disabled>
                                 <label for="object2">部门</label>
                                 <input type="radio" name="object" id="object3" value="3" class="magic-radio" <c:if test='${dispatch.object=="3"}'>checked</c:if>  disabled>
                                 <label for="object3">个人</label>
                             </div>
                         </div>
                     </div>

                     <div class="form-group">
                         <label class="col-md-2 control-label">
                             是否具有有效期<i class="fa fa-asterisk txt-color-red"></i>
                         </label>
                         <div class="col-md-6">
                             <div class="radio">
                                 <input type="radio" disabled name="hasValid" id="hasValidYes" value="1" class="magic-radio" <c:if test="${dispatch.hasValid==true}"> checked</c:if> disabled>
                                 <label for="hasValidYes">是</label>
                                 <input type="radio" disabled name="hasValid" id="hasValidNo" class="magic-radio" value="0" <c:if test="${dispatch.hasValid==false}"> checked</c:if> disabled>
                                 <label for="hasValidNo">否</label>
                             </div>
                         </div>
                     </div>

                <div class="form-group" <c:if test="${dispatch==null || dispatch.hasValid!=true}">style="display:none"</c:if> id="showValid">
                    <label class="col-md-2 control-label">
                        有效期<i class="fa fa-asterisk txt-color-red"></i>
                    </label>
                    <div class="col-md-6">
                        <input   id="validDate" name="validDate" class="form-control" disabled
                                type="text" value="<fmt:formatDate pattern="yyyy-MM-dd" value="${dispatch.validDate}" />">
                    </div>
                </div>


                <div class="form-group" <c:if test='${dispatch== null || dispatch.object!="2"}'>style="display:none"</c:if> id="showDept">
                    <label class="col-md-2 control-label">
                        通知部门<i class="fa fa-asterisk txt-color-red"></i>
                    </label>
                    <div class="col-md-6">
                        <input type="text" id="noticeDepartment" name="noticeDepartment" class="form-control" disabled
                               value="<c:forEach var="item" items="${dispatch.noticeDepartment}" varStatus="status">${item.name}<c:if test="${!status.last}">,</c:if></c:forEach>">
                        <input type="hidden" id="noticeDepartmentId" name="noticeDepartmentId"
                               value="<c:forEach var="item" items="${dispatch.noticeDepartment}" varStatus="status">${item.id}<c:if test="${!status.last}">,</c:if></c:forEach>">
                    </div>
                </div>

                <div class="form-group" <c:if test='${dispatch== null || dispatch.object!="3"}'>style="display:none"</c:if> id="showPerson">
                    <label class="col-md-2 control-label">
                        通知个人<i class="fa fa-asterisk txt-color-red"></i>
                    </label>
                    <div class="col-md-6">
                        <input type="text" id="noticeUser" name="noticeUser" class="form-control" disabled
                               value="<c:forEach var="item" items="${dispatch.noticeUsers}" varStatus="status">${item.name}<c:if test="${!status.last}">,</c:if></c:forEach>">
                        <input type="hidden" id="noticeUserId" name="noticeUserId"
                               value="<c:forEach var="item" items="${dispatch.noticeUsers}" varStatus="status">${item.id}<c:if test="${!status.last}">,</c:if></c:forEach>">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label"> 相关附件</label>
                    <div class="col-md-6">
                        <input name="uploadify" id="filename" style="display: none"  placeholder="" type="file" >
                        <input name="fileId" id="fileId" style="display: none" value="${fileId}">
                    </div>
                </div>

                 <c:if test="${stepNo>=3 || stepNo==0}">
                     <div class="form-group">
                         <label class="col-md-2 control-label">是否需要会签<i class="fa fa-asterisk txt-color-red"></i></label>
                         <div class="col-md-6">
                             <div class="radio">
                                 <input type="radio"  name="mulExam"  id="mulExamYes" value="1" class="magic-radio" <c:if test="${dispatch.mulExam==true}">checked</c:if>  <c:if test="${stepNo!=3}">disabled</c:if> >
                                 <label for="mulExamYes">是</label>
                                 <input type="radio" name="mulExam"  id="mulExamNo" class="magic-radio" value="0"  <c:if test="${dispatch.mulExam==false}">checked</c:if> <c:if test="${stepNo!=3}">disabled</c:if> >
                                 <label for="mulExamNo">否</label>
                             </div>
                         </div>
                     </div>

                     <div class="form-group" <c:if test='${dispatch == null || dispatch.mulExam!=true}'>style="display:none"</c:if> id="showExamUsers">
                         <label class="col-md-2 control-label">
                             <a href="javascript:void(0);"  onclick="fn_members_dialog_select('examUsers', 'examUsersId')" style="color: #4FA5D0">会签人员</a><i class="fa fa-asterisk txt-color-red"></i>
                         </label>
                         <div class="col-md-6">
                             <input disabled type="text" id="examUsers" name="examUsers" class="form-control" <c:if test="${stepNo!=3}">disabled</c:if>
                                    value="<c:forEach var="list" items="${dispatch.examUsers}" varStatus="status">${list.name},</c:forEach>" />
                             <input type="hidden" id="examUsersId" name="examUsersId" <c:if test="${stepNo!=3}">disabled</c:if>
                                    value="<c:forEach var="list" items="${dispatch.examUsers}" varStatus="status">${list.id},</c:forEach>" />
                         </div>
                     </div>
                     <div class="form-group">
                         <label class="col-md-2 control-label">是否需要中心领导审核<i class="fa fa-asterisk txt-color-red"></i></label>
                         <div class="col-md-6">
                             <div class="radio">
                                 <input type="radio"  name="leaderExam"  id="leaderExamYes" value="1" class="magic-radio"  <c:if test="${dispatch.leaderExam==true}">checked</c:if> <c:if test="${stepNo!=3}">disabled</c:if>>
                                 <label for="leaderExamYes">是</label>
                                 <input type="radio" name="leaderExam"  id="leaderExamNo" class="magic-radio" value="0"  <c:if test="${dispatch.leaderExam==false}">checked</c:if> <c:if test="${stepNo!=3}">disabled</c:if>>
                                 <label for="leaderExamNo">否</label>
                             </div>
                         </div>
                     </div>

                     <div class="form-group" <c:if test='${dispatch == null || dispatch.leaderExam!=true}'>style="display:none"</c:if> id="showExamObject">
                         <label class="col-md-2 control-label">中心审核对象<i class="fa fa-asterisk txt-color-red"></i></label>
                         <div class="col-md-6">
                             <div class="checkbox">
                             <c:forEach var="list" items="${examObject}" varStatus="status">
                                 <input type="checkbox" id="examObjectId${status.index}" class="magic-checkbox" name="examObjectId" value="${list.id}"  ${list.checked} <c:if test="${stepNo!=3}">disabled</c:if>>
                                 <label for="examObjectId${status.index}">${list.name}</label>
                             </c:forEach>
                             </div>
                         </div>
                     </div>
                 </c:if>

                 <c:if test='${(dispatch.processState=="Running" || dispatch.processState=="Backed") && stepNo !=1 && stepNo !=0}'>
                     <div class="form-group" id="comment">
                         <label class="col-md-2 control-label">审批意见</label>
                         <div class="col-md-6">
                             <textarea name="editor" id="editor" style="height:200px;"></textarea>
                         </div>
                     </div>
                 </c:if>
            </form>

           <div class="flow">
                <div class="panel-footer">
                    <a class="btn btn-default" id="apply-re-common" href="javascript:void(0)">
                        <i class="fa fa-lg fa-mail-reply"></i> 返回
                    </a>
                    <a class="btn btn-default"  key="ajax_edit" href="javascript:void(0);" ${isEdit}>
                        <i class="fa fa-lg fa-edit"></i> 编辑
                    </a>

                </div>
                <div class="f_title"><i class="right" id="flow"></i>流程信息</div>
                <div class="f_content" style="display:none">
                    <div id="showFlow"></div>
                </div>
                <div class="f_title"><i class="right" id="next"></i>下一步骤提示</div>
                <div class="f_content" style="display:none">
                    <div id="showNext"></div>
                </div>
            </div>

        </div>
      <div class="tab-pane fade in active" id="s2" style="margin: 10px;"></div>
    </div>
</div>


<script>
    var state = "${dispatch.processState}";
    var index = "${index}";
    var todo = "${todo}";
    var remind = "${remind}";
    var record = "${record}";
    var draft =  "${draft}";
    var stepNo = "${stepNo}";
    if(state == "Finished"){
        $('#other1').parent('li').removeClass('disabled');
    }
    var table_global_width=0;
    $("a#other1").off("click").on("click",function(e) {
        if(state == "Finished"){
            if (table_global_width == 0) {
                table_global_width = $("#s1").is(":visible") ? $("#s1").width() : $("#s2").width();
            }
            $('div').data("table_global_width", table_global_width);
            loadURL("<%=path%>/menu/com/dispatchrevise?parentId="+$("#keyId").val(),$('div#s2'));
        }else{
            return false;
        }

    });
    $(function(){
        loadURL("<%=path%>/com/running/workflow?bussinessId="+$("input#keyId").val()+"&type=flow",$('#showFlow'));
        loadURL("<%=path%>/com/running/workflow?bussinessId="+$("input#keyId").val()+"&type=next",$('#showNext'));
        __ajax_post("<%=path%>/com/running/operateType",{keyId: $("input#keyId").val()},function(pdata){
            var showDuty = false;
            var area = $("div.panel-footer");
            var edit = null;
            if (stepNo == 1){
                return false;
            }
            $(pdata.datarows).each(function(i,v){
                var str = '<a id="left_foot_btn_'+ v.action+'" class="btn btn-warning" href="javascript:void(0);"><i class="fa fa-upload">'+ v.name+'</i></a>&nbsp;';
                $(area).append(str);
                if(v.action == "approve" || v.action=="sendback"  || v.action=="deny"){
                    showDuty = true;
                }
            });
            if(showDuty == true){
                var pdata = {
                    keyId: $("input#keyId").val(),
                    entityName: "com.fz.us.oa.core.entity.com.Dispatch"
                };
                multiDuty(pdata);
            }else{
                $('#comment').hide();
            }
            if($(':visible#editor').length == 1){
                edit  = new UE.ui.Editor();
                edit.render('editor');
                /*
                 edit.ready(function() {
                 edit.setContent("");
                 });*/
            }
            //通过
            $("#left_foot_btn_approve").off("click").on("click",function(){
                var comment = "";
                if(edit != null){
                    comment = encodeURIComponent(edit.getContent());
                }
                if($.trim(comment) == ""){
                    alert("请填写审批意见");
                    return false;
                }
                var stepNo = "${stepNo}";
                if(stepNo == "3"){
                  var rs =  $("#form_dispatch_input").valid();
                  if(!rs){
                      return false;
                  }
                }
                __form_save("form_dispatch_input","<%=path%>/com/dispatch/approve?comment="+comment,function(){
                    $("#apply-re-common").trigger("click");
                })
            });
            //退回
            $("#left_foot_btn_sendback").off("click").on("click",function(){
                var comment = "";
                if(edit != null){
                    comment = encodeURIComponent(edit.getContent());
                }
                if($.trim(comment) == ""){
                    alert("请填写审批意见");
                    return false;
                }
                var vActionUrl="<%=path%>/com/dispatch/back?comment="+comment+"&curDutyId="+$('#curDutyId').val();
                var data={keyId:$("input#keyId").val()};
                __ajax_post(vActionUrl,data,function(pdata){
                    __toastr(pdata);
                    $("#apply-re-common").trigger("click");
                });
            });
            //否决
            $("#left_foot_btn_deny").off("click").on("click",function(){
                var comment = "";
                if(edit != null){
                    comment = encodeURIComponent(edit.getContent());
                }
                if($.trim(comment) == ""){
                    alert("请填写审批意见");
                    return false;
                }
                var vActionUrl="<%=path%>/com/dispatch/deny?comment="+comment+"&curDutyId="+$('#curDutyId').val();
                var data={keyId:$("input#keyId").val()};
                __ajax_post(vActionUrl,data,function(pdata){
                    __toastr(pdata);
                    $("#apply-re-common").trigger("click");
                });
            });
        });

        //流程信息展开
        $('#flow,#next').click(function(){
            if($(this).hasClass("right")){
                $(this).removeClass("right").addClass("down");
                $(this).parent(".f_title").next("div.f_content").show();
            }else{
                $(this).removeClass("down").addClass("right");
                $(this).parent(".f_title").next("div.f_content").hide();
            }
        });
    });
    //上传文件
    readLoad({
        objId:"filename",
        entityName:"fileIds",
        sourceId:"fileId"
    });
    //返回视图
    $("#apply-re-common").click(function(){

        if(index==1){
            loadURL("menu/dashboard",$('#page-content'));
        }else if(todo==1){
            loadURL("menu/toDo",$('#page-content'));
        }else if(remind==1){
            loadURL("menu/remind",$('#page-content'));
        }else if(record==1){
            loadURL("menu/taskRecord?type=1",$('#page-content'));
        }else if(record==2){
            loadURL("menu/taskRecord?type=2",$('#page-content'));
        }else if(draft==1){
            loadURL("menu/draft",$('#page-content'));
        }else{
            returnToHashUrl()
        }

    });


    //是否需要会签
    $(":radio[name='mulExam']").click(function(){
        if($(this).val() == "1"){
            $("#showExamUsers").show();
        }else{
            $("#showExamUsers").hide();
        }
    });
    //是否需要中心领导审核
    $(":radio[name='leaderExam']").click(function(){
        if($(this).val() == "1"){
            $("#showExamObject").show();
        }else{
            $("#showExamObject").hide();
        }
    });
    //编辑
    $("a[key=ajax_edit]").click(function(){
        loadURL("<%=path%>/com/dispatch/input?keyId="+$("input#keyId").val()+"&draft="+draft+"&todo="+todo+"&remind="+remind+"&record="+record+"&index="+index,$('#page-content'));
    });

    //校验
    $("#form_dispatch_input").validate({
        rules : {
            mulExam : {
                required : true
            },
            examUsersId:{
                required : function(){
                    if($(':checked[name="mulExam"]').val() == "1"){
                        return true;
                    }else{
                        return false;
                    }
                }
            },
            leaderExam:{
                required : true
            },
            examObjectId:{
                required : function(){
                    if($(':checked[name="leaderExam"]').val() == "1"){
                        return true;
                    }else{
                        return false;
                    }
                }
            }
        },
        messages : {
            mulExam : {
                required : "请选择是否需要会签"
            },
            examUsersId:{
                required : "请选择会签人员"
            },
            leaderExam:{
                required : "请选择是否需要中心领导审核"
            },
            examObjectId:{
                required : "请选择中心审核对象"
            }
        },
        ignore: "",
        errorPlacement : function(error, element) {
            if(element.is(":radio")){
                element.parents("div.inline-group").append(error);
            }else {
                error.insertAfter(element.parent());
            }
        }
    });

</script>




